﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EngineLayer.Services
{
    using DBLayer;
    using EngineLayer.Properties;
    using EngineLayer.Model;

    public class UpdatableElements
    {
        public Type ElementType { get; set; }
        public string ElementName { get; set; }
    }

    public class Updates : DBEntities, IUpdates
    {
        private List<UpdatableElements> elementsToUpdate;
     
        public Updates()
        {
            elementsToUpdate = new List<UpdatableElements>();

            elementsToUpdate.Add(new UpdatableElements
                                     { 
                                         ElementType = typeof(DBLayer.Product), 
                                         ElementName = EngineResources.PRODUCTOS
                                     }
                                 );

            elementsToUpdate.Add(new UpdatableElements
                                    {
                                        ElementType = typeof(Client),
                                        ElementName = EngineResources.CLIENTES
                                    }
                                );

            elementsToUpdate.Add(new UpdatableElements
                                    {
                                        ElementType = typeof(SystemUser),
                                        ElementName = EngineResources.USUARIOS
                                    }
                                 );
        }
        
        public DateTime GetLatestUpdateTimeStamp(ElementsToUpdate element)
        {
            string elemento = element.ToString(); 
            return database.UpdateElement.Where(n => n.Name == elemento).Select(n => n.Version).FirstOrDefault();
        }

        public List<UpdatableElements> ElementsAvailableToUpdate
        {
            get { return elementsToUpdate; }
        }
   
    }
}
